package com.gowiny.ddns.core.utils;

import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class HttpUtils {
    private static HttpClient httpClient;

    public static HttpClient getHttpClient() {
        if(null == httpClient){
            httpClient = HttpClient.newBuilder()
            		.version(HttpClient.Version.HTTP_1_1)
            		.build();
        }
        return httpClient;
    }

    public static String getString(String url){
        HttpClient httpClient = getHttpClient();
        try {
            return httpClient.send(
                    HttpRequest.newBuilder()
                            .uri(java.net.URI.create(url))
                            .build(),
                    HttpResponse.BodyHandlers.ofString()).body();
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
